use std::error::Error;

pub type BlockResult<T> = Result<T,BlockError>;

#[derive(Debug)]
pub enum BlockError {
    Byte(crate::byte::ByteError),
    Lit(crate::lit::LitError),
    Seq(crate::seq::SeqError),
}

impl std::fmt::Display for BlockError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Byte(e) => write!(f,"[block]{e}"),
            Self::Lit(e) => write!(f,"[block]{e}"),
            Self::Seq(e)  => write!(f,"[block]{e}"),
        }
    }
}

impl Error for BlockError { }

impl From<crate::byte::ByteError> for BlockError {
    fn from(value: crate::byte::ByteError) -> Self {
        Self::Byte(value)
    }
}

impl From<crate::lit::LitError> for BlockError {
    fn from(value: crate::lit::LitError) -> Self {
        Self::Lit(value)
    }
}

impl From<crate::seq::SeqError> for BlockError {
    fn from(value: crate::seq::SeqError) -> Self {
        Self::Seq(value)
    }
}